<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
        <title>学生信息管理系统</title>
		<%--制定输入框输入限制--%>
		<script type="text/javascript">
			 // 课程ID:最大只可以输入五个字符
			 // 课程名称:
			 // 课程学分:只能输入数字和符号.
			 // 课程学时:只能输入数字和符号.
			 // 课程种类:字符


			function numberRule(){
				//定义一个临时变量a
				var a=document.getElementById('number').value;
				if(a.length===6){
					alert("最大只可以输入六个字符");
				}
			}
            //检查课程编号
			//  function checkNumber(){
			// 	 var number = document.getElementById("number");
			// 	 //获取输入框的内容
			// 	 var content  = number.value;
			// 	 //用户名的规则： 两个字符必须是大写英文+4个数字
			// 	 var reg = /^[A-Z]{2}\d{4}$/;
			// 	 if(reg.test(content)){
			// 		 //符合规则
			// 		 return true;
			// 	 }else{
			// 		 //不符合规则
			// 		 number.focus();
			// 		 return false;
			// 	 }
			//  }
			//
			//  function checkName(){
			// 	 var coursename = document.getElementById("coursename");
			// 	 //获取输入框的内容
			// 	 var content  = coursename.value;
			// 	 //用户名的规则： 匹配 字母、数字、汉字 和 下划线
			// 	 var reg =/^[\w\u4e00-\u9fa5]+$/ ;
			// 	 if(reg.test(content)){
			// 		 //符合规则
			// 		 return true;
			// 	 }else{
			// 		 //不符合规则
			// 		 coursename.focus();
			// 		 return false;
			// 	 }
			//  }
			//
			//  //检查邮箱
			//  function checkCredit(){
			// 	 var coursecredit = document.getElementById("coursecredit");
			// 	 //获取输入框的内容
			// 	 var content  = coursecredit.value;
			// 	 //用户名的规则： 匹配 整数（1-15）及小数点后1位
			// 	 var reg =/^([0-9]|1[0-5])(\.[0-9])?$/;
			// 	 if(reg.test(content)){
			// 		 //符合规则
			// 		 return true;
			// 	 }else{
			// 		 //不符合规则
			// 		 coursecredit.focus();
			// 		 return false;
			// 	 }
			//  }
			//
			//  function checkPeriod(){
			// 	 var period = document.getElementById("period");
			// 	 //获取输入框的内容
			// 	 var content  = period.value;
			// 	 //用户名的规则： 匹配 （0-100）的整数及小数点后最多2位
			// 	 var reg =/^(\d{1,2}(\.\d{1,2})?|100)$/;;
			// 	 if(reg.test(content)){
			// 		 //符合规则
			// 		 return true;
			// 	 }else{
			// 		 //不符合规则
			// 		 period.focus();
			// 		 return false;
			//
			// 	 }
			//  }
			//
			//
			//
			//
			//  function checkAll(){
			// 	 var inputnumber = checkNumber();
			// 	 var inputname = checkName();
			// 	 var inputcredit = checkCredit();
			// 	 var inputperiod = checkPeriod();
			// 	 if(inputnumber&&inputname&&inputcredit&&inputperiod){
			// 		 return true;
			// 	 }else{
			// 		 return false;
			// 	 }
				 // var number = document.getElementById("number");
				 // var coursename = document.getElementById("coursename");
				 // var coursecredit = document.getElementById("coursecredit");
				 // var period = document.getElementById("period");
				 // var reg = /^[A-Z]{2}\d{4}$/;
				 // var reg1 =/^[\w\u4e00-\u9fa5]+$/ ;
				 // var reg =/^([0-9]|1[0-5])(\.[0-9])?$/;
				 // var reg =/^(\d{1,2}(\.\d{1,2})?|100)$/;



		</script>
		<!-- Favicon -->
        <link rel="shortcut icon" href="assets/img/favicon.png">
	
		<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,500;0,600;0,700;1,400&display=swap">
		
		<!-- Bootstrap CSS -->
        <link rel="stylesheet" href="assets/plugins/bootstrap/css/bootstrap.min.css">
		
		<!-- Fontawesome CSS -->
		<link rel="stylesheet" href="assets/plugins/fontawesome/css/fontawesome.min.css">
		<link rel="stylesheet" href="assets/plugins/fontawesome/css/all.min.css">
		
		<!-- Main CSS -->
        <link rel="stylesheet" href="assets/css/style.css">
    </head>
    <body>
		
		<!-- Main Wrapper -->
        <div class="main-wrapper">

			<!-- Header -->
			<!--页面头部 -->
			<div class="header">

				<!-- Logo -->
				<div class="header-left">
					<a href="index.html" class="logo">
						<img src="assets/img/logo.png" alt="Logo">
					</a>
					<a href="index.html" class="logo logo-small">
						<img src="assets/img/logo-small.png" alt="Logo" width="30" height="30">
					</a>
				</div>
				<!-- /Logo -->

				<a href="javascript:void(0);" id="toggle_btn">
					<i class="fas fa-align-left"></i>
				</a>

				<!-- Search Bar -->
				<div class="top-nav-search">
					<form>
						<input type="text" class="form-control" placeholder="搜索">
						<button class="btn" type="submit"><i class="fas fa-search"></i></button>
					</form>
				</div>
				<!-- /Search Bar -->

				<!-- Mobile Menu Toggle -->
				<a class="mobile_btn" id="mobile_btn">
					<i class="fas fa-bars"></i>
				</a>
				<!-- /Mobile Menu Toggle -->

				<!-- Header Right Menu -->
				<ul class="nav user-menu">

					<!-- Notifications -->
					<li class="nav-item dropdown noti-dropdown">
						<a href="#" class="dropdown-toggle nav-link" data-toggle="dropdown">
							<i class="far fa-bell"></i> <span class="badge badge-pill">3</span>
						</a>
						<div class="dropdown-menu notifications">
							<div class="topnav-dropdown-header">
								<span class="notification-title">通知</span>
								<a href="javascript:void(0)" class="clear-noti"> 清除</a>
							</div>
							<div class="noti-content">
								<ul class="notification-list">
									<li class="notification-message">
										<a href="#">
											<div class="media">
												<span class="avatar avatar-sm">
													<img class="avatar-img rounded-circle" alt="User Image" src="assets/img/profiles/avatar-02.jpg">
												</span>
												<div class="media-body">
													<p class="noti-details"><span class="noti-title">Carlson Tech</span> has approved <span class="noti-title">your estimate</span></p>
													<p class="noti-time"><span class="notification-time">4 mins ago</span></p>
												</div>
											</div>
										</a>
									</li>
									<li class="notification-message">
										<a href="#">
											<div class="media">
												<span class="avatar avatar-sm">
													<img class="avatar-img rounded-circle" alt="User Image" src="assets/img/profiles/avatar-11.jpg">
												</span>
												<div class="media-body">
													<p class="noti-details"><span class="noti-title">International Software Inc</span> has sent you a invoice in the amount of <span class="noti-title">$218</span></p>
													<p class="noti-time"><span class="notification-time">6 mins ago</span></p>
												</div>
											</div>
										</a>
									</li>
									<li class="notification-message">
										<a href="#">
											<div class="media">
												<span class="avatar avatar-sm">
													<img class="avatar-img rounded-circle" alt="User Image" src="assets/img/profiles/avatar-17.jpg">
												</span>
												<div class="media-body">
													<p class="noti-details"><span class="noti-title">John Hendry</span> sent a cancellation request <span class="noti-title">Apple iPhone XR</span></p>
													<p class="noti-time"><span class="notification-time">8 mins ago</span></p>
												</div>
											</div>
										</a>
									</li>
									<li class="notification-message">
										<a href="#">
											<div class="media">
												<span class="avatar avatar-sm">
													<img class="avatar-img rounded-circle" alt="User Image" src="assets/img/profiles/avatar-13.jpg">
												</span>
												<div class="media-body">
													<p class="noti-details"><span class="noti-title">Mercury Software Inc</span> added a new product <span class="noti-title">Apple MacBook Pro</span></p>
													<p class="noti-time"><span class="notification-time">12 mins ago</span></p>
												</div>
											</div>
										</a>
									</li>
								</ul>
							</div>
							<div class="topnav-dropdown-footer">
								<a href="#">View all Notifications</a>
							</div>
						</div>
					</li>
					<!-- /Notifications -->

					<!-- User Menu -->
					<li class="nav-item dropdown has-arrow">
						<a href="#" class="dropdown-toggle nav-link" data-toggle="dropdown">
							<span class="user-img"><img class="rounded-circle" src="assets/img/profiles/avatar-01.jpg" width="31" alt="Ryan Taylor"></span>
						</a>
						<div class="dropdown-menu">
							<div class="user-header">
								<div class="avatar avatar-sm">
									<img src="assets/img/profiles/avatar-01.jpg" alt="User Image" class="avatar-img rounded-circle">
								</div>
								<div class="user-text">
									<h6>Ryan Taylor</h6>
									<p class="text-muted mb-0">Administrator</p>
								</div>
							</div>
							<a class="dropdown-item" href="profile.html">我的资料</a>
							<a class="dropdown-item" href="inbox.html">邮箱</a>
							<a class="dropdown-item" href="../log/login.html">注销</a>
						</div>
					</li>
					<!-- /User Menu -->

				</ul>
				<!-- /Header Right Menu -->

			</div>
			<!-- /Header -->

			<!-- Sidebar -->
			<div class="sidebar" id="sidebar">
				<div class="sidebar-inner slimscroll">
					<div id="sidebar-menu" class="sidebar-menu">
						<ul>
							<li class="menu-title">
								<span>主菜单</span>
							</li>
							<li >
								<a href="index.html"><i class="fas fa-th-large"></i> <span>首页</span></a>
							</li>
							<li class="submenu">
								<a href="#"><i class="fas fa-user-graduate"></i> <span> 学生管理</span> <span class="menu-arrow"></span></a>
								<ul>
									<li><a href="students.jsp">查看所有学生</a></li>
<%--									<li><a href="student-details.jsp">查看学生详情</a></li>--%>
<%--									<li><a href="add-student.html">添加学生信息</a></li>--%>
<%--									<li><a href="edit-student.jsp">修改学生信息</a></li>--%>
								</ul>
							</li>
							<li>
								<a href="#"><i class="fas fa-chalkboard-teacher"></i> <span> 教师管理</span> <span class="menu-arrow"></span></a>
								<ul>
									<li><a href="teachers.jsp" >查看所有教师</a></li>
<%--									<li><a href="teacher-details.jsp">查看教师详情</a></li>--%>
<%--									<li><a href="add-teacher.html">添加教师信息</a></li>--%>
<%--									<li><a href="edit-teacher.jsp">修改教师信息</a></li>--%>
								</ul>
							</li>
<%--							<li class="submenu">--%>
<%--								<a href="#"><i class="fas fa-building"></i> <span> 院系管理</span> <span class="menu-arrow"></span></a>--%>
<%--								<ul>--%>
<%--									<li><a href="departments.html" class="active">查看所有院系</a></li>--%>
<%--									<li><a href="add-department.html">添加院系信息</a></li>--%>
<%--									<li><a href="edit-department.html">修改院系信息</a></li>--%>
<%--								</ul>--%>
<%--							</li>--%>
							<li class="submenu active">
								<a href="#"><i class="fas fa-book-reader"></i> <span> 课程管理</span> <span class="menu-arrow"></span></a>
								<ul>
									<li><a href="subjects.jsp">查看所有课程</a></li>
<%--									<li><a href="add-subject.jsp" class="active">添加课程信息</a></li>--%>
<%--									<li><a href="edit-subject.jsp">修改课程信息</a></li>--%>
								</ul>
							</li>
<%--							<li class="submenu">--%>
<%--								<a href="#"><i class="fas fa-user-graduate"></i> <span> 班级管理</span> <span class="menu-arrow"></span></a>--%>
<%--								<ul>--%>
<%--									<li><a href="clazz.html">查看所有班级</a></li>--%>
<%--									<li><a href="add-clazz.html">添加班级信息</a></li>--%>
<%--									<li><a href="edit-clazz.html">修改班级信息</a></li>--%>
<%--								</ul>--%>
<%--							</li>--%>
<%--							<li class="submenu">--%>
<%--								<a href="#"><i class="fas fa-building"></i> <span> 专业管理</span> <span class="menu-arrow"></span></a>--%>
<%--								<ul>--%>
<%--									<li><a href="major.html">查看所有专业</a></li>--%>
<%--									<li><a href="add-major.html">添加专业信息</a></li>--%>
<%--									<li><a href="edit-major.html">修改专业信息</a></li>--%>
<%--								</ul>--%>
<%--							</li>--%>
<%--							<li class="submenu ">--%>
<%--								<a href="#"><i class="fas fa-chalkboard-teacher"></i> <span> 选课管理</span> <span class="menu-arrow"></span></a>--%>
<%--								<ul>--%>
<%--									<li><a href="course.html" >查看所有选修课</a></li>--%>
<%--									<li><a href="add-course.html">添加选修课信息</a></li>--%>
<%--									<li><a href="edit-course.html">修改选修课信息</a></li>--%>
<%--								</ul>--%>
<%--							</li>--%>

							<li class="submenu ">
								<a href="#"><i class="fas fa-chalkboard-teacher"></i> <span>课程表管理</span> <span class="menu-arrow"></span></a>
								<ul>
									<li><a href="quall-class-schedule.jsp">查看课程表信息</a></li>
<%--									<li><a href="add-class-schedue.html">添加课程表信息</a></li>--%>
<%--									<li><a href="edit-class-schedule.html">修改课程表信息</a></li>--%>
								</ul>
							</li>

						</ul>
					</div>
				</div>
			</div>
			<!-- /Sidebar -->
			
			<!-- Page Wrapper -->
            <div class="page-wrapper">
                <div class="content container-fluid">
				
					<!-- Page Header -->
					<div class="page-header">
						<div class="row align-items-center">
							<div class="col">
								<h3 class="page-title">添加课程</h3>
								<ul class="breadcrumb">
									<li class="breadcrumb-item"><a href="subjects.html">课程列表</a></li>
									<li class="breadcrumb-item active">添加课程</li>
								</ul>
							</div>
						</div>
					</div>
					<!-- /Page Header -->
				
					<div class="row">
						<div class="col-sm-12">
						
							<div class="card">
								<div class="card-body">
<%--									用于与后端courseservlet连接调用register（添加）方法的接口，动作，设置提交表单事件onsubmit，验证表单中的输入项是否符合条件，复合条件时提交表单数据到数据库，不符合就禁止提交--%>
<%--									<form class="form-horizontal" action="./courses.do" method="get"  id="courses-form"  >--%>
									<form class="form-horizontal"  method="get"  id="courses-form"  >
										<input type="hidden" name="action" value="register">
										<div class="row">
											<div class="col-12">
												<h5 class="form-title"><span>课程信息</span></h5>
											</div>
											<div class="col-12 col-sm-6">  
												<div class="form-group">
													<label>课程编号</label>
<%--													获取用户输入的课程编号，并根据正则表达式判断输入是否合法&ndash;%&gt;--%>
													<span id = "numberSpan"></span>
<%--													获取用户输入的课程编号，并根据正则表达式判断输入是否合法--%>
													<input type="text" class="form-control" name="number"  id="number" maxlength="6" onkeypress="numberRule()" placeholder="最大输入6个字符（两个大写字母+四个数字）" onblur="checkNumber()"  >
													<span id = "numspan"></span>
<%--													<span id="bonumber"></span>--%>
												</div>
											</div>
											<div class="col-12 col-sm-6">
												<div class="form-group">
													<label>课程名称</label>
<%--													获取用户输入的课程编号--%>
													<span id="namespan"></span>
													<input type="text" class="form-control" name="coursename" id="coursename" onblur="checkName()" placeholder="请输入单词、字母、汉字以及下划线">
<%--													判断用户输入的课程编号是否数据库已拥有，如果已拥有提示课程已存在，如果没有则提示课程可添加--%>
													<span id="boname"></span>
												</div>
											</div>
											<div class="col-12 col-sm-6">
												<div class="form-group">
													<label>课程学分</label>
<%--													获取用户输入的课程学分，并根据正则表达式判断输入是否合法--%>
													<span id = "creditSpan"></span>
													<input type="text" class="form-control" name="coursecredit" id="coursecredit" onkeypress="courseCreditRule()" placeholder="可输入整数（1-15）及小数点后1位" onblur="checkCredit()" >
												</div>
											</div>
											<div class="col-12 col-sm-6">
												<div class="form-group">
													<label>课程学时</label>
<%--													获取用户输入的课程学时，并根据正则表达式判断输入是否合法--%>
													<span id = "periodSpan"></span>
													<input type="text" class="form-control" name="period" id="period" onkeypress="periodRule()" placeholder="可输入（0-100）的整数及小数点后最多2位"  onblur="checkPeriod()"  >
												</div>
											</div>
											<div class="col-12 col-sm-6">
												<div class="form-group">
													<label>课程类型</label>
													<span id = "typeSpan"></span>
<%--													获取用户输入的课程类型--%>
<%--													<input type="text" class="form-control" name="type" id="type"   onkeypress="typeRule()"   >--%>
<%--													<select id="type" onkeypress="typeRule()" name="type" >--%>
<%--														<option value="选修">选修</option>--%>
<%--														<option value="必修">必修</option>--%>
<%--													</select>--%>
													<select class="form-control" name="type" id="type">
																<option value="必修课" >必修课</option>
																<option value="选修课" >选修课</option>
													</select>
												</div>
											</div>
											</div>
											<div class="col-12">
												<button type="button" id="submit" class="btn btn-primary btn-subject-submit" onclick="checkAll()" >提交</button>
											</div>
									</form>
								</div>
							</div>
							
						</div>					
					</div>					
				</div>
			</div>
			<!-- /Page Wrapper -->
			
        </div>
		<!-- /Main Wrapper -->

		<!-- jQuery -->
        <script src="assets/js/jquery-3.5.1.min.js"></script>
		
		<!-- Bootstrap Core JS -->
        <script src="assets/js/popper.min.js"></script>
        <script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
		
		<!-- Slimscroll JS -->
        <script src="assets/plugins/slimscroll/jquery.slimscroll.min.js"></script>
		<script src="../../js/sweetalert.min.js" type="text/javascript"></script>
		<script src="../../js/jquery-1.11.3.min.js"></script>

		<!-- Custom JS -->
		<script src="assets/js/script.js"></script>
    </body>
</html>
<script>
	$(function () {
		//失去焦点时自动匹配正确规范的课程编号
		$('#number').blur(function () {
			var number = $('#number').val()
			var numberPatt = /^[A-Z]{2}\d{4}$/;
			if (!numberPatt.test(number)) {
				// alert("格式错误，请输入正确的课程编号")
				$('#numberSpan')[0].innerHTML = "<img src=\"../../img/wrong.png\" width=\"18\"height=\"18\">"
				$('#submit').attr("disabled",true);
				$("#numspan").text('');
			} else {
				// alert("格式正确")
				$('#numberSpan')[0].innerHTML = "<img src=\"../../img/right.png\" width=\"18\"height=\"18\">"
				$('#submit').attr("disabled",false);
				var numberText = $('#number').val().trim();
				//使用ajax 传输到后端
				$.ajax({
					url: "./courses.do",
					data: {number: numberText, action: 'isExistsNum'},
					type: "GET",
					success: function (data) {
						//回调函数
						if (data) {
							console.log(data);
							//课程名重复,提交按钮不可用
							$("#numspan").css('color', 'red');
							$("#numspan").text('课程编号已存在');
							// $('#submit').removeAttr('disabled');
							// document.getElementByIdx("btn-subject-submit").disabled=true;
							// $("#btn").attr("disabled", true);
							change_submit("false");
						} else {
							//课程名不重复
							$("#numspan").css('color', 'green');
							$("#numspan").text('课程编号可添加');
							change_submit("true");
						}
					},
					dataType: "text"
				});

			}
		})
	})


	$(function () {
		//失去焦点时自动匹配正确规范的课程名称
		$('#coursename').blur(function () {
			var name = $('#coursename').val()
			var namePatt = /^[\w\u4e00-\u9fa5]+$/;
			if (!namePatt.test(name)) {
				// alert("格式错误，请输入正确的课程编号")
				$('#namespan')[0].innerHTML = "<img src=\"../../img/wrong.png\" width=\"18\"height=\"18\">"
				$('#submit').attr("disabled",true);
				$("#boname").text('');
			} else {
				// alert("格式正确")
				$('#namespan')[0].innerHTML = "<img src=\"../../img/right.png\" width=\"18\"height=\"18\">"
				$('#submit').attr("disabled",false);
				var coursenameText = $('#coursename').val().trim();
				//使用ajax 传输到后端
				$.ajax({
					url: "./courses.do",
					data: {coursename: coursenameText, action: 'isExists'},
					type: "GET",
					success: function (data) {
						//回调函数
						if (data) {
							console.log(data);
							//课程名重复,提交按钮不可用
							$("#boname").css('color', 'red');
							$("#boname").text('课程名称已存在');
							// $('#submit').removeAttr('disabled');
							// document.getElementByIdx("btn-subject-submit").disabled=true;
							// $("#btn").attr("disabled", true);
							change_submit("false");
						} else {
							//课程名不重复
							$("#boname").css('color', 'green');
							$("#boname").text('课程可添加');
							change_submit("true");
						}
					},
					dataType: "text"
				});
			}
		})
	})



	$(function () {
		//失去焦点时自动匹配正确规范的课程学分
		$('#coursecredit').blur(function () {
			var credit = $('#coursecredit').val()
			var creditPatt =/^([0-9]|1[0-5])(\.[0-9])?$/;
			if (!creditPatt.test(credit)) {
				// alert("格式错误，请输入正确的学分")
				$('#creditSpan')[0].innerHTML = "<img src=\"../../img/wrong.png\" width=\"18\"height=\"18\">"
				$('#submit').attr("disabled",true);
			} else {
				// alert("格式正确")
				$('#creditSpan')[0].innerHTML = "<img src=\"../../img/right.png\" width=\"18\"height=\"18\">"
				$('#submit').attr("disabled",false);
			}
		})
	})

	$(function () {
		//失去焦点时自动匹配正确规范的课程学时
		$('#period').blur(function () {
			var period = $('#period').val()
			var periodPatt = /^(\d{1,2}(\.\d{1,2})?|100)$/;;
			if (!periodPatt.test(period)) {
				// alert("格式错误，请输入正确的学时")
				$('#periodSpan')[0].innerHTML = "<img src=\"../../img/wrong.png\" width=\"18\"height=\"18\">";
				$('#submit').attr("disabled",true);
			} else {
				// alert("格式正确")
				$('#periodSpan')[0].innerHTML = "<img src=\"../../img/right.png\" width=\"18\"height=\"18\">"
				$('#submit').attr("disabled",false);
			}
		})
	})


	$(function () {


		$('#submit').click(function () {
			var number = $("#number").val();
			var coursename = $("#coursename").val();
			var coursecredit= $("#coursecredit").val();
			var period = $("#period").val();
			var numberPatt = /^[A-Z]{2}\d{4}$/;
			var namePatt = /^[\w\u4e00-\u9fa5]+$/;
			var creditPatt =/^([0-9]|1[0-5])(\.[0-9])?$/;
			var periodPatt = /^(\d{1,2}(\.\d{1,2})?|100)$/;
			if($.trim(number)==null || $.trim(number)==''|| $.trim(coursename)==null|| $.trim(coursename)==''|| $.trim(period)==null|| $.trim(period)==''
					||$.trim(coursecredit)==null||$.trim(coursecredit)==''){
				swal({
					title : "添加操作提示",
					type : "error",
					text : "请检查信息是否填写完整",
					confirmButtonText : "确定",
					closeOnConfirm : false
				});
				return false;
			}
			if (!numberPatt.test(number)){
				swal({
					title : "添加操作提示",
					type : "error",
					text : "请检查课程编号是否符合标准！",
					confirmButtonText : "确定",
					closeOnConfirm : false
				});
				return false;
			}
			if (!namePatt.test(coursename)){
				swal({
					title : "添加操作提示",
					type : "error",
					text : "请检查课程名称是否符合标准！",
					confirmButtonText : "确定",
					closeOnConfirm : false
				});
				return false;
			}
			if (!creditPatt.test(coursecredit)){
				swal({
					title : "添加操作提示",
					type : "error",
					text : "请检查课程学分是否填写完整",
					confirmButtonText : "确定",
					closeOnConfirm : false
				});
				return false;
			}
			if (!periodPatt.test(period)){
				swal({
					title : "添加操作提示",
					type : "error",
					text : "请检查课程学时是否填写完整",
					confirmButtonText : "确定",
					closeOnConfirm : false
				});
				return false;
			}

			//给课程编号输入框 添加 失去焦点事件
			$('#number').blur(function () {
				var numberText = $('#number').val().trim();
				//使用ajax 传输到后端
				$.ajax({
					url: "./courses.do",
					data: {number: numberText, action: 'isExistsNum'},
					type: "GET",
					success: function (data) {
						//回调函数
						if (data) {
							console.log(data);
							//课程名重复,提交按钮不可用
							$("#numspan").css('color', 'red');
							$("#numspan").text('课程编号已存在');
							// $('#submit').removeAttr('disabled');
							// document.getElementByIdx("btn-subject-submit").disabled=true;
							// $("#btn").attr("disabled", true);
							change_submit("false");
						} else {
							//课程名不重复
							$("#numspan").css('color', 'green');
							$("#numspan").text('课程编号可添加');
							change_submit("true");
						}
					},
					dataType: "text"
				});
			});

			if($("#numspan").text()=='课程编号已存在'){
				swal({
					title : "添加操作提示",
					type : "error",
					text : "课程编号已存在！",
					confirmButtonText : "确定",
					closeOnConfirm : false
				});
				return false;
			}
			//给课程名称输入框 添加 失去焦点事件
			$('#coursename').blur(function () {
				var coursenameText = $('#coursename').val().trim();
				//使用ajax 传输到后端
				$.ajax({
					url: "./courses.do",
					data: {coursename: coursenameText, action: 'isExists'},
					type: "GET",
					success: function (data) {
						//回调函数
						if (data) {
							console.log(data);
							//课程名重复,提交按钮不可用
							$("#boname").css('color', 'red');
							$("#boname").text('课程名称已存在');
							// $('#submit').removeAttr('disabled');
							// document.getElementByIdx("btn-subject-submit").disabled=true;
							// $("#btn").attr("disabled", true);
							change_submit("false");
						} else {
							//课程名不重复
							$("#boname").css('color', 'green');
							$("#boname").text('课程可添加');
							change_submit("true");
						}
					},
					dataType: "text"
				});
			});
			if($("#boname").text()=='课程名称已存在'){
				swal({
					title : "添加操作提示",
					type : "error",
					text : "课程名称已存在！",
					confirmButtonText : "确定",
					closeOnConfirm : false
				});
				return false;
			}

			$.ajax({
				url:'./courses.do',
				data:$('#courses-form').serialize(),
				type:'get',
				success:function (data) {
					console.log("进来了")
					if (data==1){
						swal({
							title: '添加成功',
							icon: 'success'
						}).then(function () {
							$.ajax({
								url:'./courses.do',
								type:'get',
								data:{
									action:'queryAll',
								},
								success:function (data) {
									location.href='./courses.do?action=queryAll'
								}
							})

						})
					}else{
						swal({
							title: '添加失败',
							icon: 'error'
						})
					}

				}
			})
		})

	})


</script>







<script>
	//给课程名输入框 添加获得焦点事件
	    $('#coursename').focus(function () {
		$("#boname").css('color', 'gray');
		$("#boname").text('请输入课程名');
	});

	    // 绑定事件，当提示课程名称重复时禁止提交，若可添加则允许提交
	function change_submit(zt) {
		if (zt == "false") {
			//alert("提交按钮不可用");
			document.getElementById("submit").disabled=true;
		} else {
			//alert("恢复正常");
			document.getElementById("submit").disabled=false;
		}
	}



</script>

